<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>充值</title>
    <script src="__INDEX__/js/mui.min.js"></script>
	<link href="__INDEX__/css/mui.min.css" rel="stylesheet" />
	<link rel="stylesheet" href="__INDEX__/css/iconfont.css" />
	<link rel="stylesheet" href="__INDEX__/css/style.css" />
	<link rel="stylesheet" href="__INDEX__/css/mall.css" />	
</head>
<body>
	
	<div class="mui-content gljcz_content">
	    {include file="public/member" /}
	    <form id="my_form" class="layui-form update_form" action="{:url('member/to_pay')}" method="post">
	    	<input type="hidden" id="cz" name="cz" value="0" />
		    <div class="glj_czbt">请选择充值金额</div>
		    <ul class="glj_czlist clearfix">
		    	<li  data-val=100>
		    		<a href="#">
		    			<p class="rmb">100元</p>
		    		</a>
		    	</li>
		    	<li data-val=200>
		    		<a href="#">
		    			<p class="rmb">200元</p>
		    		</a>
		    	</li>
		    	<li data-val=500>
		    		<a href="#">
		    			<p class="rmb">500元</p>
		    		</a>
		    	</li>
		    	<li data-val=1000>
		    		<a href="#">
		    			<p class="rmb">1000元</p>
		    		</a>
		    	</li>
		    	<li data-val=2000>
		    		<a href="#">
		    			<p class="rmb">2000元</p>
		    		</a>
		    	</li>
		    	<li data-val=5000>
		    		<a href="#">
		    			<p class="rmb">5000元</p>
		    		</a>
		    	</li>
		    </ul>
		     <div class="glj_czbt">{if isset($recharge_config)}{$recharge_config|html_entity_decode}{/if}</div>
		    <div class="gerzl_btn gerzl_btn2" id="btn"><a href="#">确定</a></div>
	    </form>
	</div>
</body>
{include file="public/footer" /}
<script>
	$(".glj_czlist li").click(function(){
		$(".active").removeClass("active");
		$(this).addClass("active");
		$("#cz").val($(this).data('val'));
	})
	$("#btn").click(function(){
		var cz_money=$(".active").data("val");
		if(cz_money==undefined){
			layer.msg("请选择充值金额");
			return;
		}else{
			$(this).attr('disabled',true);
			var btnArray = ['不同意', '同意'];
				mui.confirm('您确认操作?', '充值须知', btnArray, function(e) {
					 if (e.index == 1) {
					 	$.ajax({
							type: "post",
							data: {
								money: cz_money
							},
							url: "/index/payment/cz_pay",
							success: function(data) {
								data = JSON.parse(data);
								callpay(data);
							}
						});
					 }
			})
			
		}
		
	})
		//调用微信JS api 支付
	function jsApiCall(jsApiParameters) {
		WeixinJSBridge.invoke('getBrandWCPayRequest', jsApiParameters,
			function(res) {
				if(res.err_msg == "get_brand_wcpay_request:ok") {
					layer.msg('支付成功', {
					  icon: 1,
					  time: 1500 //2秒关闭（如果不配置，默认是3秒）
					}, function(){
						 window.location = "/index/member"; 
					}); 
				} else {
					layer.msg("支付失败")
				}
				
			}
		);
	}

	function callpay(jsApiParameters) {
		if(typeof WeixinJSBridge == "undefined") {
			if(document.addEventListener) {
				document.addEventListener('WeixinJSBridgeReady', jsApiCall(jsApiParameters), false);
			} else if(document.attachEvent) {
				document.attachEvent('WeixinJSBridgeReady', jsApiCall(jsApiParameters));
				document.attachEvent('onWeixinJSBridgeReady', jsApiCall(jsApiParameters));
			}
		} else {
			jsApiCall(jsApiParameters);
		}
	}
</script>
</html>
